const express = require('express');
const user = express.Router();
const connection = require("../config");

user.get('/user/list', (req, res) => {
    //查询语句
    let sql = `select * from user where 1=1 order by id asc`
    console.log(sql)
    connection.query(sql, function (err, result) {
        if (err) {
            console.log('[SELECT ERROR]:', err.message);
        }
        let new_result = [];
        if (result.length) {
            new_result = result.map(item => {
                let {id, username} = item;
                return {uid: id, nickname: username}
            });
        }
        console.log(new_result,0)
        res.send({data:new_result, status: new_result.length ? 1 : 0}) //数据库查询结果返回到result中,把查询数据发送到客户端
    });
})

module.exports = user;